def replace2(x):
str = ''
if x[0] != 'a':
str += 'hi' + x[1:len(x) - 1]
else:
str += x[:len(x) - 1]
if x[len(x) - 1] != 'z':
str += 'hi'
else:
str += x[len(x) - 1]
return str
Function Call | Return Value | |||
---|---|---|---|---|
replace2('a hello ') | → | |||
replace2('goodbyez') | → | |||
replace2('aworldz') | → | |||
replace2('oof') | → | |||
replace2('az') | → | |||
replace2(' ') | → |
Experiment with this code on Gitpod.io